|
|
|
|
|
|
|
Practical guidelines for implementing the Error-Processing and Exception-Handling Subsystem in order to minimize the risk of unnecessary application failure |
|
|
|
|
|
|
|
|
How to incorporate the subsystem into the Samsona Bank Teller System example |
|
|
|
|
|
|
|
|
An Overview of the Error-Processing and Exception-Handling Subsystem |
|
|
|
|
|
|
|
|
Perhaps it could go without mentioning that a serious application, whether for deployment on the Internet, a corporate intranet, or desktop, requires that all errors and exceptions be properly trapped. A quality application allows no fatal flaws, and few minor bugs. This lesson discusses error processing and exception handling and how to encapsulate these methods in classes. |
|
|
|
|
|
|
|
|
Error handling includes the trapping and the subsequent chain of responses to errors in your application. Each significant class method and code module function (if any) requires initial error handling. Only the simplest methods that have been well tested or are otherwise no-brainers should be considered candidates for skipping inline error handling. Implementing inline error handling in your methods requires you to do the following: |
|
|
|
|
|
|
|
|
1. Enable the error trap (equivalent to throwing an exception). |
|
|
|
|
|
|
|
|
2. Respond to the error (equivalent to catching an exception). |
|
|
|
|
|
|
|
|
3. Complete the error-handling process and, if possible, continue program execution. |
|
|
|
|
|
|
|
|
Step 1 activates an error trap by informing the application what inline code to execute as an error occurs. In order to inform Visual Basic of what code to invoke, you use the On Error statement. The On Error statement initiates your error traps, specifying to which label the application should go to perform the beginning of the error-handling routine. |
|
|
|
|
|
|
|
|
Step 2 implies writing an inline error-handling routine that responds to the errors that occur in a given method. It's in the inline routine that you invoke a method on an object whose class you create at design time to handle the attribute values of the Err object. It's advisable not to do too much complex error handling within a method as this could clutter your method code and make it difficult to debug. Besides, you want to be able to reuse sophisticated error-handling routines throughout your application. |
|
|
|
|
|
|
|
|
Step 3 marks the completion of error handling and the resuming of code execution, if possible. The Resume statement tells your application to continue process instructions (lines of code) at the line where the error occurred. Visual Basic then retries that line of code. If the error condition has not been properly resolved, then the error-handling operation is initiated again. If your application continually encounters a problem that you feel |
|
|
|
|
|